package com.xiaohu.demo;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.basic.BasicButtonUI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI.NormalColor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.jiaorui.text.Main;

/**
 * 经纬仪
@author XiaoHu
@date 2018-10-24
 */
public class Theodolite extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel topLabel;
	private JPanel leftPanel;
	private JPanel rightPanel;
	private JPanel endJPanel;
	private JMenuBar menuBar;
	private JButton stopButton;
	private static JButton startButton;
	private JButton fileButton;
	private JButton aboutButton;
	private JButton zantingButton;
	private JButton pcmButton;
	private JButton gpsButton;
	private JButton exitButton;
	private JLabel leftJLabel;
	private Timer timer;
	private String DEFAULT_TIME_FORMAT = "HH:mm:ss.SSS";
	private JTextField timeField;
	private boolean bool;
	private JScrollPane showJScrollPane;
	private static JTextArea  showField;
	private JTextField A_text;
	private JTextField R_text;
	private JTextField status_text;
	private JTextField E_text;
	private JTextField f_text;
	private JLabel locationJLable;
	private JLabel shine;
	private Icon grey;
	private Icon green; 
	private String format; 
	private JLabel rember;
	private JLabel gps;
	private JLabel pcm;
	private JLabel lowHZJLabel;
	private JLabel highHZJLabel;
	private JLabel midHZJLabel;
	private String hzSize;  //记录频率大小
	private static JLabel vField;
	private JLabel fwLabel;
	private JLabel fyLabel;
	private JLabel jlLabel;
	private Log log;
	
	
	public Theodolite(){
		setLookAndFeel();
		bool = false;
		init();
	}
	
	/**
	 * 初始化
	 */
	public void init(){
		this.setUndecorated(true);//去边框处理
		this.setLayout(null);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);//最大化
		this.setResizable(false);//不能改变大小
		this.setAlwaysOnTop(true);//总在最前面
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container mainContainer = this.getContentPane();
		
		//标题标签
		topLabel = new JLabel(" 经纬仪多区域联合仿真样机-Theodolite multi-area joint simulation prototype");
		topLabel.setOpaque(true);//设置不透明
		topLabel.setBounds(0,0,mainContainer.getWidth(),20);
		topLabel.setBackground(Color.GRAY);
		topLabel.setForeground(Color.white);
		mainContainer.add(topLabel);
		
		
		//菜单栏
		JMenuBar menuBar = addMenuBar();
		menuBar.setBounds(0,21,mainContainer.getWidth(),62);
		mainContainer.add(menuBar);
		addListener();
		
		//信息显示区（左侧）
		leftPanel = new JPanel();
		leftPanel.setOpaque(false);
		leftPanel.setLayout(null);
		leftPanel.setBounds(2, 85,795,514);
		leftPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		mainContainer.add(leftPanel);
		
		leftJLabel = new JLabel();
		leftJLabel.setBounds(2,0,795,514);
		Icon icon = new ImageIcon("./image/show1.png");
		leftJLabel.setIcon(icon);
		leftJLabel.setOpaque(true);
		leftPanel.add(leftJLabel);
		
		
		
		
		//操控区（右侧）
		rightPanel = new JPanel();
		rightPanel.setBounds(800, 85, 565, 514);
		rightPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		rightPanel.setLayout(null);
		mainContainer.add(rightPanel);
		
		JLabel titleJLabel = new JLabel("光电跟踪测量设备");
		titleJLabel.setBounds(45,8, 460, 60);
		titleJLabel.setFont(new Font("华文琥珀", Font.ROMAN_BASELINE, 35));
		rightPanel.add(titleJLabel);
		
		JLabel titJLabel = new JLabel("Photoelectric tracking and measuring equipment");
		titJLabel.setBounds(35,60, 460, 30);
		titJLabel.setFont(new Font("Harlow Solid Italic", Font.ROMAN_BASELINE, 23));
		rightPanel.add(titJLabel);
		
		//标志
		Icon Bzicon = new ImageIcon("./image/jingweiyi.png");
		JLabel BzLabel = new JLabel(Bzicon);
		BzLabel.setBounds(470,0,100,95);
		BzLabel.setOpaque(false);
		rightPanel.add(BzLabel);
		
		
		JPanel timeJPanel = new JPanel();
		timeJPanel.setLayout(null);
		timeJPanel.setBackground(Color.DARK_GRAY);
		timeJPanel.setBounds(20,98,520,80);
		timeJPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		rightPanel.add(timeJPanel);
		
		timeField = new JTextField("00:00:00.000");
		timeField.setBounds(300, 10, 200, 60);
		timeField.setBackground(Color.black);
		timeField.setForeground(Color.white);
		timeField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
		timeField.setFont(new Font("宋体", Font.ROMAN_BASELINE, 31));
		timeJPanel.add(timeField);
		setTime();
		
        
        //显示操作记录
        showJScrollPane = new JScrollPane();
        showJScrollPane.setLayout(null);
        showJScrollPane.setBounds(15,183,530,130);
        showJScrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
        showField = new JTextArea();
        showField.setBounds(3,3,521,123);
        showField.setBorder(BorderFactory.createLoweredBevelBorder());
        showJScrollPane.add(showField);
        rightPanel.add(showJScrollPane);
        
        //点亮(激光) 
  		grey = new ImageIcon("./image/grey.png");
  		green = new ImageIcon("./image/green.png");
  		shine = new JLabel();
  		shine.setBounds(28,15,35,35);
  		shine.setIcon(grey);
  		shine.setOpaque(false);
  		timeJPanel.add(shine);
  		JLabel shineText = new JLabel("激光");
  		shineText.setBounds(28,40,40,40);
  		shineText.setForeground(Color.WHITE);
  		timeJPanel.add(shineText);
  		
  		//点亮(记录)
  		rember = new JLabel();
  		rember.setBounds(90,15,35,35);
  		rember.setIcon(grey);
  		rember.setOpaque(false);
  		timeJPanel.add(rember);
  		JLabel remberText = new JLabel("记录");
  		remberText.setBounds(90,40,40,40);
  		remberText.setForeground(Color.WHITE);
  		timeJPanel.add(remberText);
  		
    	//点亮(GPS)
  		gps = new JLabel();
  		gps.setBounds(214,15,35,35);
  		gps.setIcon(grey);
  		gps.setOpaque(false);
  		timeJPanel.add(gps);
  		JLabel gpsText = new JLabel("上/下电");
  		gpsText.setBounds(210,40,40,40);
  		gpsText.setForeground(Color.WHITE);
  		timeJPanel.add(gpsText);
  		
  		//点亮(Status)
  		pcm = new JLabel();
  		pcm.setBounds(152,15,35,35);
  		pcm.setIcon(grey);
  		pcm.setOpaque(false);
  		timeJPanel.add(pcm);
  		JLabel pcmText = new JLabel("跟踪状态");
  		pcmText.setBounds(142,40,80,40);
  		pcmText.setForeground(Color.WHITE);
  		timeJPanel.add(pcmText);
	
		//显示信息窗口      转台参数列表
		JPanel showParam = new JPanel();
		showParam.setBounds(15,325,530,170);
		showParam.setBorder(BorderFactory.createTitledBorder("转台位置设置"));
		rightPanel.add(showParam);
		showParam.setLayout(null);
		
		
		JLabel A = new JLabel("方位角/A");
	    A.setBounds(20, 45, 80, 30);
		//A.setSize(new Dimension(80,30));
		A.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		showParam.add(A);
		A_text = new JTextField("253°34′49″");
		A_text.setBackground(Color.lightGray);
		A_text.setBounds(120,45, 100, 30);
		A_text.setFont(new Font("宋体", Font.ROMAN_BASELINE, 14));
		showParam.add(A_text);
		A_text.getDocument().addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				fwLabel.setText("方位  "+A_text.getText());
			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				fwLabel.setText("方位  "+A_text.getText());
			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				fwLabel.setText("方位  "+A_text.getText());
			}
		});
		 
		 JLabel R = new JLabel("俯仰角/R");
		 R.setBounds(260, 45, 80, 30);
		 R.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		 showParam.add(R);
		 R_text = new JTextField("253°34′49″");
		 R_text.setBackground(Color.lightGray);
		 R_text.setFont(new Font("宋体", Font.ROMAN_BASELINE, 14));
		 R_text.setBounds(360, 45, 100, 30);
		 showParam.add(R_text);
		 R_text.getDocument().addDocumentListener(new DocumentListener() {
				
				@Override
				public void removeUpdate(DocumentEvent e) {
					fyLabel.setText("俯仰  "+R_text.getText());
				}
				
				@Override
				public void insertUpdate(DocumentEvent e) {
					fyLabel.setText("俯仰  "+R_text.getText());
				}
				
				@Override
				public void changedUpdate(DocumentEvent e) {
					fyLabel.setText("俯仰  "+R_text.getText());
				}
			});
		 
		 JLabel E = new JLabel("焦距/f");
		 E.setBounds(20, 100, 80, 30);
		 E.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		 showParam.add(E);
		 E_text = new JTextField("");
		 E_text.setBackground(Color.lightGray);
		 E_text.setFont(new Font("宋体", Font.ROMAN_BASELINE, 14));
		 E_text.setBounds(120, 100, 100, 30);
		 showParam.add(E_text);
		
		 JLabel f = new JLabel("距离/R");
		 f.setBounds(260, 100, 80, 30);
		 f.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		 showParam.add(f);
		 f_text = new JTextField("00.000 Km");
		 f_text.setBackground(Color.lightGray);
		 f_text.setFont(new Font("宋体", Font.ROMAN_BASELINE, 14));
		 f_text.setBounds(360, 100, 100, 30);
		 showParam.add(f_text);
		 f_text.getDocument().addDocumentListener(new DocumentListener() {
				
				@Override
				public void removeUpdate(DocumentEvent e) {
					jlLabel.setText("距离  "+f_text.getText());
				}
				
				@Override
				public void insertUpdate(DocumentEvent e) {
					jlLabel.setText("距离  "+f_text.getText());
				}
				
				@Override
				public void changedUpdate(DocumentEvent e) {
					jlLabel.setText("距离  "+f_text.getText());
				}
			});
		 
		
		//信息显示
		JLabel ztJLabel = new JLabel("转台位置:");
		fwLabel = new JLabel("方位  253°34′49″");
		fyLabel = new JLabel("俯仰  253°34′49″");
		jlLabel = new JLabel("距离  00.000 Km");
		
		JLabel ydJLabel = new JLabel("引导信息:");
		JLabel fwLabel1 = new JLabel("方位  253°34′49″");
		JLabel fyLabel1 = new JLabel("俯仰  253°34′49″");
		JLabel jlLabel1 = new JLabel("距离  00.000 Km");
		
		JLabel sunJLabel = new JLabel("太阳 [253°34′49″]");
		JLabel monJLabel = new JLabel("月亮 [253°34′49″]:");
		JLabel wareJLabel = new JLabel("太阳警告 [安全警告]");
		
		
		ztJLabel.setForeground(Color.white);
		ztJLabel.setBounds(580, 80, 100, 20);
		ztJLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		fwLabel.setForeground(Color.white);
		fwLabel.setBounds(580, 100, 200, 30);
		fwLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));

		fyLabel.setForeground(Color.white);
		fyLabel.setBounds(580, 120, 200, 30);
		fyLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		jlLabel.setForeground(Color.white);
		jlLabel.setBounds(580, 140, 200, 30);
		jlLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		ydJLabel.setForeground(Color.white);
		ydJLabel.setBounds(580, 200, 200, 30);
		ydJLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		fwLabel1.setForeground(Color.white);
		fwLabel1.setBounds(580, 220, 200, 30);
		fwLabel1.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));

		fyLabel1.setForeground(Color.white);
		fyLabel1.setBounds(580, 240, 200, 30);
		fyLabel1.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		jlLabel1.setForeground(Color.white);
		jlLabel1.setBounds(580, 260, 200, 30);
		jlLabel1.setFont(new Font("宋体", Font.ROMAN_BASELINE, 15));
		
		sunJLabel.setForeground(Color.white);
		sunJLabel.setBounds(590, 320, 200, 30);
		sunJLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 12));
		
		monJLabel.setForeground(Color.white);
		monJLabel.setBounds(590, 340, 200, 30);
		monJLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 12));
		
		wareJLabel.setForeground(Color.white);
		wareJLabel.setBounds(590, 360, 200, 30);
		wareJLabel.setFont(new Font("宋体", Font.ROMAN_BASELINE, 12));

		
		leftJLabel.add(ztJLabel);
		leftJLabel.add(fwLabel);
		leftJLabel.add(fyLabel);
		leftJLabel.add(jlLabel);
		leftJLabel.add(ydJLabel);
		leftJLabel.add(fwLabel1);
		leftJLabel.add(fyLabel1);
		leftJLabel.add(jlLabel1);
		leftJLabel.add(sunJLabel);
		leftJLabel.add(monJLabel);
		leftJLabel.add(wareJLabel);
		
		//坐标展示  2, 85,795,514
		locationJLable = new JLabel();
		locationJLable.setBorder(BorderFactory.createLoweredBevelBorder());
		locationJLable.setBounds(2,575,795,216);
		Icon icon1 = new ImageIcon("./image/zuobiao.png");
		locationJLable.setIcon(icon1);
		locationJLable.setOpaque(true);
		mainContainer.add(locationJLable);
		
		
		Graphics g = locationJLable.getGraphics();
		//paint(g);
				
		//右下角板块
		endJPanel = new JPanel();
		endJPanel.setBounds(801,575,563,216);
		endJPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		endJPanel.setLayout(null);
		mainContainer.add(endJPanel);
		
		//频率
		JPanel hZJPanel = new JPanel();
		hZJPanel.setLayout(null);
		hZJPanel.setBackground(Color.DARK_GRAY);
		hZJPanel.setBounds(15,30,530,155);
		hZJPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		endJPanel.add(hZJPanel);
		
		JLabel hZJLabel = new JLabel("激光频率");
		hZJLabel.setBounds(10, 10, 80, 30);
		hZJLabel.setForeground(Color.WHITE);
		hZJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		hZJPanel.add(hZJLabel);
		
		lowHZJLabel = new JLabel("10Hz");
		lowHZJLabel.setBounds(150, 10, 80, 30);
		lowHZJLabel.setForeground(Color.WHITE);
		lowHZJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 16));
		midHZJLabel = new JLabel("25Hz");
		midHZJLabel.setBounds(250, 10, 80, 30);
		midHZJLabel.setForeground(Color.gray);
		midHZJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 16));
		highHZJLabel = new JLabel("50Hz");
		highHZJLabel.setBounds(350, 10, 80, 30);
		highHZJLabel.setForeground(Color.gray);
		highHZJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 16));
		
		JLabel turnJLabel = new JLabel();
		turnJLabel.setBackground(Color.white);
		turnJLabel.setBounds(450,10,24, 24);
		Icon icon2 = new ImageIcon("./image/turn.png");
		turnJLabel.setIcon(icon2);
		turnJLabel.setOpaque(false);
		turnJLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				//循环点亮
				if(StateHandler.State==1){
					//点亮10HZ
					lowHZJLabel.setForeground(Color.WHITE);
					highHZJLabel.setForeground(Color.gray);
					hzSize = "10";
				}
				if(StateHandler.State==2){
					//点亮25HZ
					midHZJLabel.setForeground(Color.WHITE);
					lowHZJLabel.setForeground(Color.gray);
					hzSize = "25";
				}
				if(StateHandler.State==3){
					//点亮50HZ
					highHZJLabel.setForeground(Color.WHITE);
					midHZJLabel.setForeground(Color.gray);
					hzSize = "50";
				}
				StateHandler.flipState();
			}
			
		});
		
		//目标速度  
		JLabel vJLabel = new JLabel("目标高度");
		vField = new JLabel("0  m/s");
		vJLabel.setBounds(10, 55, 80, 30);
		vJLabel.setForeground(Color.WHITE);
		vJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		vField.setBounds(151, 55, 80, 30);
		vField.setForeground(Color.WHITE);
		vField.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		
		//目标坐标
		JLabel LoJLabel = new JLabel("目标坐标");
		LoJLabel.setBounds(10, 100, 80, 30);
		LoJLabel.setForeground(Color.WHITE);
		LoJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		JLabel xJLabel = new JLabel("X: 0");
		xJLabel.setForeground(Color.WHITE);
		xJLabel.setBounds(150, 100, 80, 30);
		xJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		JLabel yJLabel = new JLabel("Y: 0");
		yJLabel.setBounds(250, 100, 80, 30);
		yJLabel.setForeground(Color.WHITE);
		yJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		JLabel zJLabel = new JLabel("Z: 0");
		zJLabel.setBounds(350, 100, 80, 30);
		zJLabel.setForeground(Color.WHITE);
		zJLabel.setFont(new Font("华文中宋", Font.ROMAN_BASELINE, 18));
		
		
		
		
		hZJPanel.add(lowHZJLabel);
		hZJPanel.add(midHZJLabel);
		hZJPanel.add(highHZJLabel);
		hZJPanel.add(highHZJLabel);
		hZJPanel.add(turnJLabel);
		hZJPanel.add(vJLabel);
		hZJPanel.add(vField);
		hZJPanel.add(LoJLabel);
		hZJPanel.add(xJLabel);
		hZJPanel.add(yJLabel);
		hZJPanel.add(zJLabel);
		
		
		Icon fJicon = new ImageIcon("./image/feiji.png");
		JLabel fJLabel = new JLabel(fJicon);
		fJLabel.setBounds(150,150,40,40);
		fJLabel.setOpaque(false);
		leftJLabel.add(fJLabel);
		
		//打开监听
		String StringXML = "com/jiaorui/JMSdemo/TopicConsumerXML.xml";
		ApplicationContext context = new ClassPathXmlApplicationContext(StringXML);
		
		//打开日志记录
		log = LogFactory.getLog(this.getClass());
		
		//重绘
		this.repaint();
	
	}
	
	/**
	 * 创建菜单栏
	 * @return
	 */
	private JMenuBar addMenuBar() {
		menuBar = new JMenuBar();
		menuBar.setLayout(null);
		startButton = createBtn("打开激光", "./image/start.png");
		startButton.setBorder(BorderFactory.createRaisedBevelBorder());
		stopButton = createBtn("关闭激光", "./image/stop.png");
		stopButton.setBorder(BorderFactory.createRaisedBevelBorder());
		fileButton = createBtn("数据文件", "./image/file.png");
		fileButton.setBorder(BorderFactory.createRaisedBevelBorder());
		aboutButton = createBtn("开始记录", "./image/about.png");
		aboutButton.setBorder(BorderFactory.createRaisedBevelBorder());
		zantingButton = createBtn("暂停记录", "./image/zanting.png");
		zantingButton.setBorder(BorderFactory.createRaisedBevelBorder());
		pcmButton = createBtn("PCM", "./image/pcm.png");
		pcmButton.setBorder(BorderFactory.createRaisedBevelBorder());
		gpsButton = createBtn("GPS", "./image/gps.png");
		gpsButton.setBorder(BorderFactory.createRaisedBevelBorder());
		exitButton = createBtn("退出", "./image/exit.png");
		exitButton.setBorder(BorderFactory.createRaisedBevelBorder());
		startButton.setBounds(0,2,60,57);
		stopButton.setBounds(61,2,60,57);
		fileButton.setBounds(130,2,60,57);
		aboutButton.setBounds(191,2,60,57);
		zantingButton.setBounds(251,2,60,57);
		pcmButton.setBounds(312,2,60,57);
		gpsButton.setBounds(373,2,60,57);
		exitButton.setBounds(442,2,60,57);
		// 增加按钮
		menuBar.add(startButton);
		menuBar.add(stopButton);
		menuBar.add(fileButton);
	    menuBar.add(aboutButton);
		menuBar.add(exitButton);
		menuBar.add(zantingButton);
		menuBar.add(pcmButton);
		menuBar.add(gpsButton);
		
		return menuBar;
	}
	
	/**
	 * 设置时间
	 */
	public void setTime(){
		timer = new Timer();
		timer.schedule(new TimerTask() {
			SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);
			@Override
			public void run() {
				format = dateFormatter.format(new Date());
				if(bool){
					timeField.setText(format);
				}
			}
		}, 0, 1);
	}

	/**创建按钮
	 * @param text
	 * @param icon
	 * @return
	 */
	private JButton createBtn(String text, String icon) {
		ImageIcon imageIcon = new ImageIcon(icon);
		JButton btn = new JButton(text, imageIcon);
		btn.setUI(new BasicButtonUI());// 恢复基本视觉效果
		btn.setPreferredSize(new Dimension(80, 27));// 设置按钮大小
		btn.setContentAreaFilled(false);// 设置按钮透明
		btn.setFont(new Font("粗体", Font.PLAIN, 10));// 按钮文本样式
		btn.setMargin(new Insets(0, 0, 0, 0));// 按钮内容与边框距离
		btn.setVerticalTextPosition(JButton.BOTTOM);
		btn.setHorizontalTextPosition(JButton.CENTER);
		return btn;
	}

	
	/**
	 * 设置皮肤
	 */
	private void setLookAndFeel() {
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	/**
	 * 添加监听
	 */
	private void addListener() {
		
		
		startButton.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e){
				System.out.println("打开");
		    }
		});
		
		/**
		 * 打开激光
		 */
		startButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				startButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				startButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				
				/*bool = true;
				shine.setIcon(green);
				showField.append("  "+format +"[操作手]：启动激光"+"\r\n");
				log.info("  "+format +"[操作手]：启动激光");*/
			}
		});
		stopButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				stopButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				stopButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			public void mouseClicked(MouseEvent e) {
				bool = false;
				shine.setIcon(grey);
				rember.setIcon(grey);
				showField.append("  "+format +"[操作手]：关闭激光"+"\r\n");
				log.info("  "+format +"[操作手]：关闭激光");
			}
		});
		fileButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				fileButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				fileButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {}
		});
		aboutButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				aboutButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				aboutButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				if(bool==true){
					rember.setIcon(green);
					showField.append("  "+format +"[操作手]：开始记录"+"\r\n");
				}
			}
		});
		exitButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				exitButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				exitButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				System.exit(0);
			}
		});
		zantingButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				zantingButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				zantingButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				if(bool==true){
					rember.setIcon(grey);
					showField.append("  "+format +"[操作手]：关闭记录"+"\r\n");
				}
			}
		});
		zantingButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				zantingButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				zantingButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				if(bool==true){
					rember.setIcon(grey);
					showField.append("  "+format +"[操作手]：关闭记录"+"\r\n");
				}
			}
		});
		gpsButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				gpsButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				gpsButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				if(bool==true){
					gps.setIcon(grey);
					showField.append("  "+format +"[操作手]：开启GPS"+"\r\n");
				}
			}
		});
		pcmButton.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {}
			@Override
			public void mousePressed(MouseEvent e) {}
			@Override
			public void mouseExited(MouseEvent e) {
				//鼠标移出
				pcmButton.setBorder(BorderFactory.createRaisedBevelBorder());
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//鼠标移进时
				pcmButton.setBorder(BorderFactory.createLoweredBevelBorder());
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				if(bool==true){
					pcm.setIcon(grey);
					showField.append("  "+format +"[操作手]：开启PCM"+"\r\n");
				}
			}
		});
	}
	
	/**
	 * 设置速度
	 * @param v
	 */
	public static void setVField(String v){
		vField.setText(v+"  m/s");
	}
	
	public static void click(){
		startButton.doClick();
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
	}
	

	public static void main(String[] args) {
		Theodolite theodolite = new Theodolite();
		//设置速度
		new Thread(new VutilsThread(theodolite)).start();
		theodolite.repaint();
	}
}
